package io.in.inputstream.demo01;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

//InputStream字节输入流的顶晨父类,是一个抽象类
//用于数据读取
public class InputStreamDemo01 {

    //入口
    public static void main(String[] args) throws IOException {
        //多态创建一个InputStream对象
        InputStream inputStream = new FileInputStream("G:\\heima\\itheima-hello-git\\Day10\\src\\io\\in\\inputstream\\demo01\\test.txt");

        //一次读取一个字节
        /*int read = inputStream.read();
        while (read != -1){
            System.out.print((char)read);
            read= inputStream.read();
        }*/

        /*int by = -1 ;           //by 作用就是读取字节
        while ((by = inputStream.read())!=-1){
            System.out.print((char)by);*/

        //一起去读取一个数组
        byte[] bytes = new byte[5];
        /*int read = inputStream.read(bytes);     //返回值代表有效读取字节个数
       // System.out.println(new String(bytes));


        while (read!=-1){
            System.out.print(new String(bytes));
            read =inputStream.read(bytes);
        }*/
        int len = -1;
        while ((len = inputStream.read(bytes))!=-1){

            System.out.print(new String(bytes));
        }



        //一次读取一个字符数组,返回值代表可读取有效字节个数,最后返回值为-1.
        //byte []bytes = new byte[3];

        //int read = inputStream.read(bytes);


        //释放资源
        inputStream.close();

    }



}



